#include "big_buf_impl.h"
#include "../global/head.h"
#include "../xos/head.h"
#include "../msg/head.h"

/////////////////////////////////////////////////////////////////////////////////////////
// 
namespace xos
{
    big_buf_impl::big_buf_impl()
    {
        m_nLen = 0;
        m_nPos = 0;
    }

    big_buf_impl::~big_buf_impl()
    {
        term();
    }

    ////////////////////////////////////////////////////////////////////////////////////
    // 

    int big_buf_impl::init()
    {
        int nRet = 0;
        return nRet;
    }

    int big_buf_impl::term()
    {
        int nRet = 0;

        m_nLen = 0;
        m_nPos = 0;

        return nRet;
    }

    ////////////////////////////////////////////////////////////////////////////////////
    // 

    // 
    // read data
    // 
    char * big_buf_impl::get_data( char * lpszData, int nLen, int * lpnLenNeeded )
    {
        if( lpnLenNeeded )
        {
            *lpnLenNeeded = m_nLen;
        }

        if( lpszData )
        {
            memcpy( lpszData, m_szBuf + m_nPos, m_nLen );
        }

        return m_szBuf + m_nPos;
    }

    // 
    // set data
    // 
    int big_buf_impl::set_data( const char * lpszData, int nLen )
    {
        memcpy( m_szBuf, lpszData, nLen );
        m_nLen = nLen;
        m_nPos = 0;
        return nLen;
    }

    // 
    // get data len
    // 
    int big_buf_impl::get_len( int * lpnDataLen )
    {
        if( lpnDataLen )
        {
            *lpnDataLen = m_nLen;
        }

        return m_nLen;
    }

    // 
    // set data len
    // 
    int big_buf_impl::set_len( int nLen )
    {
        int nRet = 0;
        m_nLen = nLen;
        return nRet;
    }

    // 
    // get data pos
    // 
    int big_buf_impl::get_pos( int * lpnPos )
    {
        if( lpnPos )
        {
            *lpnPos = m_nPos;
        }

        return m_nPos;
    }

    // 
    // set data pos
    // 
    int big_buf_impl::set_pos( int nPos )
    {
        int nRet = 0;
        m_nPos = nPos;
        return nRet;
    }

    // 
    // get buf size. total buf size
    // 
    int big_buf_impl::get_buf_size( int * lpnBufLen )
    {
        if( lpnBufLen )
        {
            *lpnBufLen = sizeof( m_szBuf );
        }

        return sizeof( m_szBuf );
    }

    // 
    // release
    // 
    int big_buf_impl::release()
    {
        int nRet = 0;

        term();
        put_back_lock();

        return nRet;
    }
} // xos
